package org.wevil.repo;

import org.wevil.entity.news.NewsSubject;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface NewsSubjectRepo extends BaseRepo<NewsSubject, Integer> {

    List<NewsSubject> findByPid(Integer pid);

    List<NewsSubject> findByIdIn(List<Integer> ids);

    @Modifying
    @Query("update NewsSubject t set " +
            "t.name = case when :#{#entity.name} is null then t.name else :#{#entity.name} end, " +
            "t.pid = case when :#{#entity.pid} is null then t.pid else :#{#entity.pid} end, " +
            "t.order = case when :#{#entity.order} is null then t.order else :#{#entity.order} end, " +
            "t.type = case when :#{#entity.type} is null then t.type else :#{#entity.type} end " +
            "where t.id = :#{#entity.id}")
    int update(NewsSubject entity);
}
